package com.baymax.study.base.beanLifeCycle;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * MyBeanPostProcess
 *
 * @author Baymax
 * @since 2024-03-23
 */
@Component
public class MyBeanPostProcess implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (StringUtils.equals(beanName, "myUserBean")) {
            System.out.println("[05]初始化前置处理器: BeanPostProcessor#postProcessBeforeInitialization");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (StringUtils.equals(beanName, "myUserBean")) {
            System.out.println("[07]初始化后置处理器: BeanPostProcessor#postProcessAfterInitialization");
        }
        return bean;
    }
}
